/*
 * @Author: 胡伟 3247249228@qq.com
 * @Date: 2022-06-29 14:21:25
 * @LastEditors: 胡伟 3247249228@qq.com
 * @LastEditTime: 2022-07-24 10:23:55
 * @FilePath: \first-project\project\src\main.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugin/element'
import './assets/global.css'
import './assets/icon/iconfont.css'
import axios from 'axios'
import 'default-passive-events'
import './Format'
import scroll from 'vue-seamless-scroll'
// import './assets/icons/svg/iconfont.svg'
Vue.use(scroll)
import i18n from './lang/index'
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)
// 导入NProgress包对应的js和css
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// axios拦截器
// 在request中展示进度条  NProgress.start()
axios.interceptors.request.use(config => {
  NProgress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 在最后必须 return config
  return config
})
// 在response拦截器中, 隐藏进度条  NProgress.done()
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

axios.defaults.baseURL = 'https://jk.huwei6.com/api'

Vue.prototype.$http = axios

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  // 防止刷新后vuex里丢失标签列表tagList
  store.commit('getMenu')
  let token = window.sessionStorage.getItem('token')
  // 过滤登录页，防止死循环
  if (!token && to.name !== 'login') {
    next({ name: 'login' })
  } else {
    next()
  }
})

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
